package experiment1;

public class NextDate {

    private static final String ERROR_INFO = "Invalid date";

    public static String theNextDate(int year, int month, int day) {
        if (!(1900 <= year && year <= 2050 && 1 <= month && month <= 12 && 1 <= day && day <= 31))
            return ERROR_INFO;
        switch (month) {
            case 1:case 3:case 5:case 7:case 8: case 10:
                if (day < 31)
                    day = day + 1;
                else {
                    day = 1;
                    month = month + 1;
                }
                break;
            case 4: case 6: case 9: case 11:
                if (day < 30)
                    day = day + 1;
                else {
                    day = 1;
                    month = month + 1;
                }
                break;
            case 12:
                if (day < 31)
                    day = day + 1;
                    // return year+"年" + month+"月" + day+"日";
                else {
                    day = 1;
                    month = 1;
                    if (year == 2050)
                        return ERROR_INFO;
                    else
                        year = year + 1;
                }
                break;
            case 2:
                if (day < 28)
                    day = day + 1;
                if (day == 28 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0))
                    day = day + 1;
                else {
                    day = 1;
                    month = 3;
                }
                break;
            default:
                return ERROR_INFO;
        }
        return year + "年" + month + "月" + day + "日";
    }
}
